package com.xyh.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xyh.po.Student;
import com.xyh.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author:kyle
 * @Date:2020/12/23 - 11:45
 * @Project:spring_StudentsDormitoryManagementSystem
 * @Package:com.xyh.controller
 * @Version:1.0
 */
@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/school/xs")
    public String listStudent(HttpServletRequest request){
        String studentName = request.getParameter("studentName");
        String className = request.getParameter("className");
        String address = request.getParameter("address");
        List<Student> students = null;
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        if(studentName == null || className == null || address== null){
            students= studentService.queryStudentByWrapper(wrapper);
        }else{

            wrapper.like("student_name",studentName).and(i->i.like("class_name",className)).and(i->i.like("address",address));

            students = studentService.queryStudentByWrapper(wrapper);
        }

        request.setAttribute("students",students);
        return "student";
    }
}
